package com.zlkj.pro.core.annotation.impl;

import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 孙铭泽
 * @date 2020-10-29
 * @time 10:26
 **/
@Component
public class FileJsonDeserializeImpl extends JsonDeserializer<String> {


    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String filePath = ConfigContext.me().getConfigValueNullable("OSS_ALIYUN_OSS_DOMAIN_NAME", String.class) + "/";
        int length = filePath.length();
        String[] split = p.getText().split(",");
        StringBuilder sb = new StringBuilder();
        for (String s : split) {
            if (s.contains(filePath)) {
                sb.append(s, length, s.length()).append(",");
            } else {
                sb.append(s).append(",");
            }
        }
        return StrUtil.strip(sb.toString(), ",");
    }
}
